package com.atguigu.tingshu.user.api;

import com.atguigu.tingshu.common.anno.GuiGuLogin;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.model.user.UserInfo;
import com.atguigu.tingshu.model.user.UserPaidTrack;
import com.atguigu.tingshu.user.service.UserInfoService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Tag(name = "用户管理接口")
@RestController
@RequestMapping("api/user/userInfo")
@SuppressWarnings({"unchecked", "rawtypes"})
public class UserInfoApiController {

    @Autowired
    private UserInfoService userInfoService;

    @Operation(summary = "更新Vip到期失效状态")
    @GetMapping("updateVipExpireStatus")
    public Result updateVipExpireStatus(){
        userInfoService.updateVipExpireStatus();
        return Result.ok();
    }

    @Operation(summary = "通过用户Id获取到主播信息")
    @GetMapping("getUserInfoById/{userId}")
    public Result<UserInfo> getUserInfoById(@PathVariable(value = "userId") Long userId) {
        UserInfo userInfo = userInfoService.getUserInfoById(userId);
        return Result.ok(userInfo);
    }

    @Operation(summary = "判断用户是否购买了该专辑下的声音")
    @GuiGuLogin(required = false)
    @PostMapping("userIsPaidTrack/{albumId}")
    public Result<Map<Long, Long>> userIsPaidTrack(@PathVariable("albumId") Long albumId, @RequestBody List<Long> trackIdList) {
        Map<Long, Long> map = userInfoService.userIsPaidTrack(albumId, trackIdList);
        return Result.ok(map);
    }

    @Operation(summary = "判断用户是否购买了该专辑")
    @GetMapping("isPaidAlbum/{albumId}/{userId}")
    public Result<Boolean> isPaidAlbum(@PathVariable(value = "albumId") Long albumId,@PathVariable(value = "userId") Long userId){
        Boolean result = userInfoService.isPaidAlbum(albumId,userId);
        return Result.ok(result);
    }

    @GuiGuLogin
    @Operation(summary = "查询用户购买过的声音集合")
    @GetMapping("findUserTrackPaidList/{albumId}")
    public Result<List<Long>> findUserTrackPaidList(@RequestBody Long albumId) {
        List<Long> trackIdList = userInfoService.findUserTrackPaidList(albumId);
        return Result.ok(trackIdList);
    }

}

